import requests#type: ignore
import json
import base64
import capture
from iamtoken import get_token
url = "https://image.cn-north-4.myhuaweicloud.com/v2/7703c099b8f5485985140d72ce89715a/image/media-tagging"

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials#type: ignore
from huaweicloudsdkimage.v2.region.image_region import ImageRegion#type: ignore
from huaweicloudsdkcore.exceptions import exceptions#type: ignore
from huaweicloudsdkimage.v2 import *#type: ignore
from config import ak,sk,timeit
@timeit('red')
def main():
    base64str = capture.main("labelrecog.png")
    credentials = BasicCredentials(ak, sk)
    client = ImageClient.new_builder().with_credentials(credentials).with_region(ImageRegion.value_of("cn-north-4")).build()#type: ignore
    try:
        request = RunImageMediaTaggingRequest()#type: ignore
        request.body = ImageMediaTaggingReq(#type: ignore
            image=base64str

        )
        response = client.run_image_main_object_detection(request)
        print(response)
        return response
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
        return None
if __name__ == "__main__":
    main()